#include "X.h"
#include <thread>
#include <iostream>

static mutex ecran;

static void thread1(const X& x1, const X& x2) {
	if (x1 == x2) {
		lock_guard<mutex> g(ecran);
		cout << "deux instances sont egales" << endl;
	} else {
		lock_guard<mutex> g(ecran);
		cout << "deux instances ne sont pas egales : " << x1 << " != " << x2 << endl;
	}
}

static void thread2(X& x1, X& x2) {
	swap(x1, x2);
	lock_guard<mutex> g(ecran);
	cout << "Valeurs echangees" << endl;
}

int main(int argc, char** argv) {
	X x1(3);
	X x2(3);
	X x3(7);
	thread t1(thread1, ref(x1), ref(x2));
	thread t2(thread2, ref(x1), ref(x3));
	t1.join();
	t2.join();
	return 0;
}

